<template>
	
	<view>		

		<QSPickerCustom2
		ref="passTypePicker"
		required
		:name="formName" 
		variableName="passType" 
		v-model="passType"
		title="通行证类型" 
		@change="passTypeChange"
		:steps="steps"/>
		
		<QSPickerCustom2
		ref="carTypePicker"
		required
		:name="formName" 
		variableName="carType" 
		v-model="carType"
		title="号牌种类"
		@change="carTypeChange"
		:steps="steps"/>
		
		<QSPickerCustom2
		ref="startAddressPicker"
		required
		:name="formName" 
		variableName="startAddress" 
		title="入城点"  
		:steps="steps"/>
		
		<!-- <QSInput :name="formName" variableName="startAddress" title="入城点" required v-model="values.startAddress" :itemDisabled="itemDisabled"></QSInput>
		 -->
		 <QSInput :name="formName" 
		  ref="endAddressRef"
		 variableName="endAddress" 
		 title="目的地" 
		 required 
		 v-model="values.endAddress" 
		 :itemDisabled="itemDisabled">
		 </QSInput>
		
		<QSPickerDate :name="formName" 
		variableName="appStartTime" 
		title="开始时间"
		required
		:dataSet="dateTimeSet"
		:value="values.appStartTime"  
		placherhold="请选择" />
		
		<QSPickerDate :name="formName"
		variableName="appEndTime" 
		required
		title="结束时间"
		:dataSet="dateTimeSet"
		:value="values.appStartTime"  
		placherhold="请选择" />
		
		<QSKeyboardPlate :name="formName"
		ref="carNumRef"
		variableName="carNum" 
		title="车牌号"
		height= "0.65"
		required
		:value="values.carNum"
		@change="carNumChange"
		placherhold="请输入车牌号" />
		
		<!-- <QSInput :name="formName" 
			ref="carNumRef"
			variableName="carNum" 
			title="车牌号" 
			required 
			verifyType="CarNum"
			v-model="values.carNum" 
			:itemDisabled="itemDisabled">
		</QSInput> -->
		<QSRadio :name="formName" 
			ref="subordinateTypeRef"
			variableName="subordinateType" 
			value="0"
			title="个人/单位" 
			color= '#f5105c'
			:itemArray="subordinateUnitItemArray"
			contentLayout="left"
			v-model="values.subordinateType"
			@change="subordinateUnitRadioChange"
			:itemDisabled="itemDisabled">
		</QSRadio>
		<QSInput :name="formName" 
			ref="subordinateUnitRef"
			variableName="subordinateUnit"
			:title="subordinateUnitTitle"
			required
			v-model="values.subordinateUnit"
			:itemDisabled="itemDisabled">
		</QSInput>
		<view class="dirver-info-box">
			<text class="title">驾驶员信息</text>
			<QSInput :name="formName" 
				ref="driverNameRef"
				variableName="driverName"
				title="姓名"
				placeholder="请输入驾驶员姓名"
				required
				verifyType="Required"
				v-model="values.driverName"
				:itemDisabled="itemDisabled">
			</QSInput>
			<QSInput :name="formName"
				ref="contactNumberRef"
				variableName="contactNumber" 
				title="联系电话"
				placeholder="请输入驾驶员联系电话"
				verifyType="Tel"
				required v-model="values.contactNumber"
				:itemDisabled="itemDisabled">
				</QSInput>
			<QSInput :name="formName" 
			ref="driverIdCardRef"
				variableName="driverIdCard" 
				title="身份证号"
				placeholder="请输入驾驶员身份证号"
				verifyType="idCart"
				required
				v-model="values.driverIdCard"
				:itemDisabled="itemDisabled">
			</QSInput>
		</view>
		<QSTextarea :name="formName" 
			ref="appTheReasonRef"
			variableName="appTheReason"
			title="申请理由"
			placeholder="请输入申请理由: 运输XXX货物到XXX地点"
			required 
			verifyType="Required"
			v-model="values.appTheReason"
			:itemDisabled="itemDisabled">
		</QSTextarea>
		
		<block v-if="updatePics">
			<block v-for="(item, index) in picsItemArray" :key="index">
				<block v-if="item.type == 'QSPics'">
					<QSPics 
						v-if = "item.required"
						:name="picsFormName"
						:ref="item.fieldName + 'PicsInf'"
						:variableName="item.fieldName + 'PicsInf'"
						:title="item.fieldCnName"
						v-model="item.vModeData"
						@imageChoosed="imageChoosed"
						>
					</QSPics>
				</block>
				<block v-else>
					<QSInfinitePics 
						v-if = "item.required"
						:name="picsFormName"
						:ref="item.fieldName + 'PicsInf'"
						:variableName="item.fieldName + 'PicsInf'"
						:title="item.fieldCnName"
						v-model="item.vModeData"
						@imageChoosed="imageChoosed"
						>
					</QSInfinitePics>
				</block>
			</block>
		</block>
		
		
		
		
		
		<!-- <button type="primary" style="margin-top: 50rpx;margin-bottom:50rpx;width: 50%;" @tap="uploadPicsTest">上传图片</button>
		 -->
		<button type="primary" style="margin-top: 50rpx;margin-bottom:50rpx;width: 50%;" @tap="commitForm">提交申请</button>
	
	</view>
	
	
	
</template>

<script>
	import uniIcons from '@/components/uni-ui/uni-icons/uni-icons.vue'
	
	
	import QSApp from '@/components/QS-inputs-split/js/app.js';
	export default {
		components: {
			uniIcons,
		},
		data() {
			return {
				isCommiting: false,
				title: 'Hello',
				formName: 'applyInput',
				carType: {},
				passType: {},
				steps: {
					step_1_value: "name", //第一级显示的属性名
				},
				subordinateUnitItemArray: [
						{
							name: '个人申请',
							value: '0',
						},
						{
							name: '单位申请',
							value: '1'
						}
				],
				subordinateUnitTitle:"车主姓名",
				subordinateUnitPicsTitle: "个人申请表",
				picsFormName: 'picInput',
				values: {
					passType: '',
					carType: '',
					startAddress: '',
					endAddress: '',
					appStartTime: '',
					appEndTime: '',
					carNum: '',
					subordinateType:'0',
					subordinateUnit: '',
					driverName: '',
					contactNumber: '',
					driverIdCard: '',
					appTheReason: ''
				},
				dateTimeSet:{
					startYear:2019,
					endYear:2090,
					dateMode:4,
					dateFormatArray:['-', '-', ' ', ':', ':']
				},
				itemDisabled: false,
				
				passTypePickerData:[],
				carTypePickerData:[],
				startAddressPickerData:[],
				
				nCode: '',
				updatePics: true,
				picsItemArray:[
					{
						required: false,
						type: "QSInfinitePics",
						vModeData:[],
						
						fieldName: 'spb',
						fieldCnName: '审批表',
						fieldSort: 1010,
					},
					{
						required: false,
						type: "QSPics",
						vModeData:[
							{
								title: '正面（国徽）', 
								required: true,
								//path: "http://jj.kman.gov.cn/zdcl-wx/upimg/2020/09/08/20/0bc9cdcc-b069-4f4a-8b5f-c6eb05edbc57.jpg"
							}, 
							{
								title: '反面（头像）',
								required: true,
							 }
						],
						
						fieldName: 'sfz',
						fieldCnName: '身份证',
						fieldSort: 1020,
					},
					{
						required: false,
						type: "QSPics",
						vModeData:[
							{
								title: '正面（主页）', 
								required: true,
								// path: "http://www.dogroot.com/zdcl-wx/upimg/2020/08/22/00/a4206dc6-f04c-4dc7-9466-4b1a62cdb082.jpg"
							}, 
							{
								title: '反面（副页）',
								required: true,
							 }
						],
						
						fieldName: 'jsz',
						fieldCnName: '驾驶证',
						fieldSort: 1030,
					},
					{
						required: false,
						// type: "QSPics",
						// vModeData:[
						// 	{
						// 		title: '正面（主页）', 
						// 		required: true,
						// 		// path: "http://www.dogroot.com/zdcl-wx/upimg/2020/08/22/00/a4206dc6-f04c-4dc7-9466-4b1a62cdb082.jpg"
						// 	}, 
						// 	{
						// 		title: '反面（副页）',
						// 		required: true,
						// 	 }
						// ],
						vModeData:[],
						
						fieldName: 'xsz',
						fieldCnName: '行驶证',
						fieldSort: 1040,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'jqx',
						fieldCnName: '交强险保单',
						fieldSort: 1050,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'sybx',
						fieldCnName: '商业保险',
						fieldSort: 1060,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'sqb',
						fieldCnName: '申请',
						fieldSort: 1070,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'dwzm',
						fieldCnName: '单位证明',
						fieldSort: 1080,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'dlysz',
						fieldCnName: '道路运输证',
						fieldSort: 1090,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'cyzgz',
						fieldCnName: '从业资格证',
						fieldSort: 1100,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'aqjcbg',
						fieldCnName: '安全检测报告',
						fieldSort: 1110,
					},
					{
						required: false,
						vModeData:[],
						
						fieldName: 'yyzz',
						fieldCnName: '营业执照',
						fieldSort: 1120,
					},
				],
				uploadErrCount:0,
				reqId: null,
				inBlackList: false,
				curCarNum:'',
			}
		},
		onReady() {
			//this.setPickerData();
			console.log("passApply onReady...");
			this.loadDicts();
		},
		onLoad(options){
			let _this = this;
			console.log("passApply onLoad...");
			console.log(options);
			
			if(options==null){
				return;
			}
			//debugger;
			if(options.id)
				_this.reqId = options.id;
		},
		onShow(){
			console.log("passApply onShow...");
		},
		methods: {
			subordinateUnitRadioChange(value){
				let _this = this;
				
				console.log('Radio更新:' + JSON.stringify(value));
				if(value=='1'){
					_this.subordinateUnitTitle = '单位名称';
					_this.subordinateUnitPicsTitle = '单位申请表';
				}else if(value=='0'){
					_this.subordinateUnitTitle = '车主姓名';
					_this.subordinateUnitPicsTitle = '个人申请表';
				}
			},
		
			passTypeChange(value){
				let _this = this;
				
				console.log('passType change:' + JSON.stringify(value));
				//{"data":[{"name":"6天及以上通行证","value":"2"}],"value":[1]}
				console.log('passType vmode:' + JSON.stringify(_this.passType));
				
				// if(value.data[0].name == "1-5天临时通行证"){
					
				// }else if(value.data[0].name == "6天及以上通行证"){
					
				// }
				if(_this.passType.data != undefined && 
					_this.carType.data != undefined)
					_this.updatePicsForm(_this.passType.data[0].name,_this.carType.data[0].name)
			},
			carTypeChange(value){
				let _this = this;
				console.log('carType change:' + JSON.stringify(value));
				//{"data":[{"name":"黄牌大型汽车","value":"大型汽车"}],"value":[]}
				console.log('carType vmode:' + JSON.stringify(_this.carType));
				if(_this.passType.data != undefined &&
					_this.carType.data != undefined)
					_this.updatePicsForm(_this.passType.data[0].name,_this.carType.data[0].name)
			},
			carNumChange(value){
				let _this = this;
				console.log('carNum change:' + JSON.stringify(value));
				
				_this.curCarNum = value.data;
				let url = "/rest/inBlackList";
				
				_this.$api.request(url,
				 {
					carNum:  value.data
				 },
				 failres => {
					// uni.showToast({
					// 	title: '验证黑名单失败',
					// 	icon: "none"
					// });
				}).then(rsp => {
					console.log(JSON.stringify(rsp));
					if(rsp.data.inBlackList){
						uni.showModal({
							title: '提示',
							content: _this.curCarNum+'已经被加入黑名单，请到交警大队处理',
							showCancel: false,
							confirmText: '确认',
							success: (e) => {
								if (e.confirm) {
								}
							},
							fail: () => {},
							complete: () => {}
						})
					}
					_this.inBlackList = rsp.data.inBlackList;
				})
			},
			updatePicsForm(passType,carType){
				let _this = this;
				
				if(passType=='1-5天临时通行证'){
					_this.updatePicsItem("spb",true);
					_this.updatePicsItem("sfz",true);
					_this.updatePicsItem("jsz",true);
					_this.updatePicsItem("xsz",true);
					_this.updatePicsItem("jqx",true);
					
					_this.updatePicsItem("sybx",false);
					_this.updatePicsItem("sqb",false);
					_this.updatePicsItem("dwzm",false);
					_this.updatePicsItem("dlysz",false);
					_this.updatePicsItem("cyzgz",false);
					_this.updatePicsItem("aqjcbg",false);
					_this.updatePicsItem("yyzz",false);
					
				}else if(passType=='6天及以上通行证'){
					if(carType == "黄牌大型汽车"){
						_this.updatePicsItem("spb",true);
						_this.updatePicsItem("sfz",true);
						_this.updatePicsItem("jsz",true);
						_this.updatePicsItem("xsz",true);
						_this.updatePicsItem("jqx",true);
						
						_this.updatePicsItem("sybx",true);
						_this.updatePicsItem("sqb",true);
						_this.updatePicsItem("dwzm",true);
						_this.updatePicsItem("dlysz",true);
						_this.updatePicsItem("cyzgz",true);
						_this.updatePicsItem("aqjcbg",true);
						_this.updatePicsItem("yyzz",true);
					}else if(carType == "蓝牌小型汽车"){
						_this.updatePicsItem("spb",true);
						_this.updatePicsItem("sfz",true);
						_this.updatePicsItem("jsz",true);
						_this.updatePicsItem("xsz",true);
						_this.updatePicsItem("jqx",true);
						
						_this.updatePicsItem("sybx",true);
						_this.updatePicsItem("sqb",true);
						
						_this.updatePicsItem("dwzm",true);
						
						_this.updatePicsItem("dlysz",false);
						_this.updatePicsItem("cyzgz",false);
						_this.updatePicsItem("aqjcbg",false);
						
						_this.updatePicsItem("yyzz",true);
					}else if(carType == "黄绿牌大型新能源汽车"){
						_this.updatePicsItem("spb",true);
						_this.updatePicsItem("sfz",true);
						_this.updatePicsItem("jsz",true);
						_this.updatePicsItem("xsz",true);
						_this.updatePicsItem("jqx",true);
						
						_this.updatePicsItem("sybx",true);
						_this.updatePicsItem("sqb",true);
						_this.updatePicsItem("dwzm",true);
						_this.updatePicsItem("dlysz",true);
						_this.updatePicsItem("cyzgz",true);
						_this.updatePicsItem("aqjcbg",true);
						_this.updatePicsItem("yyzz",true);
					}else if(carType == "绿牌小型新能源汽车"){
						_this.updatePicsItem("spb",true);
						_this.updatePicsItem("sfz",true);
						_this.updatePicsItem("jsz",true);
						_this.updatePicsItem("xsz",true);
						_this.updatePicsItem("jqx",true);
						
						_this.updatePicsItem("sybx",true);
						_this.updatePicsItem("sqb",true);
						
						_this.updatePicsItem("dwzm",true);
						
						_this.updatePicsItem("dlysz",false);
						_this.updatePicsItem("cyzgz",false);
						_this.updatePicsItem("aqjcbg",false);
						
						_this.updatePicsItem("yyzz",true);
					}
				}
			},
			updatePicsItem(fieldName,required){
				let _this = this;
				
				_this.picsItemArray.forEach(item=>{
					if(item.fieldName == fieldName){
						item.required = required
					}
				})
			},
			getPicsCnName(variableName,index){
				let _this = this;
				
				let cnName = '';
				_this.picsItemArray.forEach(item=>{
					if(item.fieldName+'PicsInf' == variableName){
						cnName = item.fieldCnName
						
						if(item.type === 'QSPics'){
							cnName+=item.vModeData[index].title
						}
					}
					
				})
				
				return cnName;
			},
			imageChoosed(res){
				let _this = this;
			
			
				
			
				console.log('选择图片:' + JSON.stringify(res));
				const variableName = res.variableName;
				const index = res.index;
				const inf = _this.$refs[variableName][0];
				const cnName = _this.getPicsCnName(variableName,index);
				
				console.log("cnName"+cnName)
				
				if(_this.inBlackList){
					uni.showModal({
						title: '提示',
						content: _this.curCarNum+'已经被加入黑名单，请到交警大队处理',
						showCancel: false,
						confirmText: '确认',
						success: (e) => {
							if (e.confirm) {
								inf.clearPicApi(index)
							}
						},
						fail: () => {},
						complete: () => {}
					})
					return;
				}
				
				/*
				  错误1
					上传成功:[{"path":"blob:http://localhost:8080/1388e3fb-06a8-49c5-b550-6d443e1b7ff4","upLoadResult":[null,{"errMsg":"uploadFile:ok","statusCode":500,"data":"{\n\t\"code\":500,\n\t\"data\":\"\",\n\t\"exceptionClazz\":\"\",\n\t\"message\":\"\\u670D\\u52A1\\u5668\\u5F02\\u5E38\",\n\t\"success\":false\n}"}]}] 
				  错误2
				    {}
					statusCode 不存在
				*/
				
				inf.setUpLoadData({fileDescribe: cnName});
				const upload = inf.getUpLoadPromiseArray();
				upload.then(res=>{
					let succes = true;
					
					console.log('上传成功:' + JSON.stringify(res));
					if(res == undefined || !res instanceof Array ||
						res.length <= index ||
						res[index].upLoadResult == undefined ||
						res[index].upLoadResult[1].statusCode != 200){
							succes = false;
						}
						try{
							let uploadRsp = JSON.parse(res[index].upLoadResult[1].data);
							if(uploadRsp.code!=200){
								succes = false;
							}
						}catch(err){
							console.log(err);
							succes = false;
						}
						//上传失败
						if(!succes){
							// uni.showToast({
							// 	title: "上传失败:"+JSON.stringify(res),
							// 	icon: "none"
							// });
							uni.showModal({
								title: '错误提示',
								content: cnName + '上传失败，请重拍上传',
								showCancel: false,
								confirmText: '确认',
								success: (e) => {
									if (e.confirm) {
										inf.clearPicApi(index)
									}
								},
								fail: () => {},
								complete: () => {}
							})
							
						}
					//console.log('上传成功:' + JSON.stringify(_this.picsItemArray));
				}).catch(err=>{
					console.log('上传失败:' + JSON.stringify(err));
					uni.showModal({
						title: '错误提示',
						content: cnName + '上传失败，请重拍上传',
						showCancel: false,
						confirmText: '确认',
						success: (e) => {
							if (e.confirm) {
								inf.clearPicApi(index)
							}
						},
						fail: () => {},
						complete: () => {}
					})
					
				})
			},
			checkPicsFormRequired(){
				let _this = this;
				let result = true;
			
				for(let j= 0;j<_this.picsItemArray.length;j++){
					let item = _this.picsItemArray[j];
					let tip = item.fieldCnName;
					if(item.required != true)
						continue
					try{
						if(item.type === "QSPics"){
							console.log(JSON.stringify(item.vModeData))
							for(let i=0;i<item.vModeData.length;i++){
								tip = item.fieldCnName + item.vModeData[i].title;
								if(item.vModeData[i].preFile)
									continue;
								if(item.vModeData[i].upLoadResult == undefined ||
									item.vModeData[i].upLoadResult == null
								){
									uni.showToast({
										title: "请上传"+tip,
										icon: "none"
									});
									return false;
								}
								
								if(item.vModeData[i].upLoadResult[1].statusCode!=200){
									uni.showToast({
										title: "上传"+tip+"失败，请重新选择",
										icon: "none"
									});
									return false;
								}
								
								let uploadRsp = JSON.parse(item.vModeData[i].upLoadResult[1].data);
								if(uploadRsp.code != 200){
									uni.showToast({
										title: "上传"+tip+"失败，请重新选择",
										icon: "none"
									});
									return false;
								}
							}
						}else{
							//infinitePics
							let num = 0;
							for(let i=0;i<item.vModeData.length;i++){
								if(item.vModeData[i].preFile){
									num++;
								}else{
									let uploadRsp = JSON.parse(item.vModeData[i].upLoadResult[1].data);
									if(uploadRsp.code == 200){
										num++;
									}
								}
							}
							
							if(num<=0){
								result = false;
								uni.showToast({
									title: "至少上传一张"+item.fieldCnName+"图片",
									icon: "none"
								});
								
								break;
							}
						}
					}catch(err){
						uni.showToast({
							title: tip+"图片上传出错:"+err,
							icon: "none"
						});
						result = false;
						break;
					}
				}
				
				
				return result;
			},
			genPicsForm(){
				let _this = this;
				//num = _this.genPicsForm(_this.spbPics,_this.spbPicsFormData,allPicsForm);
				let allPicsForm = [];
					
					_this.picsItemArray.forEach(item=>{
						if(item.required){
							if(item.type === "QSPics"){
								for(let i=0;i<item.vModeData.length;i++){
									if(item.vModeData[i].preFile){
										allPicsForm.push(
											{
												sort: i,
												fieldType: 101,
												fieldName: item.fieldSort+"_"+item.fieldName,
												fieldCnName: item.fieldCnName+item.vModeData[i].title,
												fieldValue: item.vModeData[i].id
											}
										);
									}else{
										let uploadRsp = JSON.parse(item.vModeData[i].upLoadResult[1].data);
										if(uploadRsp.code == 200){
											allPicsForm.push(
												{
													sort: i,
													fieldType: 101,
													fieldName: item.fieldSort+"_"+item.fieldName,
													fieldCnName: item.fieldCnName+item.vModeData[i].title,
													fieldValue: uploadRsp.data.id
												}
											);
										}
									}
								}
							}else{
								for(let i=0;i<item.vModeData.length;i++){
									if(item.vModeData[i].preFile){
										allPicsForm.push(
											{
												sort: i,
												fieldType: 101,
												fieldName: item.fieldSort+"_"+item.fieldName,
												fieldCnName: item.fieldCnName,
												fieldValue: item.vModeData[i].id
											}
										);
									}else{
										let uploadRsp = JSON.parse(item.vModeData[i].upLoadResult[1].data);
										if(uploadRsp.code == 200){
											allPicsForm.push(
												{
													sort: i,
													fieldType: 101,
													fieldName: item.fieldSort+"_"+item.fieldName,
													fieldCnName: item.fieldCnName,
													fieldValue: uploadRsp.data.id
												}
											);
										}
									}
								}
							}
						}
					})
				
				return allPicsForm;
			},
			commitForm_T(){
				let _this = this;
				QSApp.getForm(_this.formName).then(res=>{
					console.log('获取表单数据成功:' + JSON.stringify(res));
					if(res.verifyErr.length>0){
						let errInput = res.verifyErr[0];
						QSApp.showToast(errInput.title + "输入不正确");
						return;
					}
				}).catch(err=>{
					console.log('获取表单数据失败:' + JSON.stringify(err));
				
					uni.showToast({
						title: "数据失败:"+JSON.stringify(err),
						icon: "none"
					});
				});
			},
			commitForm(){
				let _this = this;
				let num = 0;
				let allPicsForm = [];
				
				if(_this.inBlackList){
					uni.showModal({
						title: '提示',
						content: _this.curCarNum+'已经被加入黑名单，请到交警大队处理',
						showCancel: false,
						confirmText: '确认',
						success: (e) => {
							if (e.confirm) {
							}
						},
						fail: () => {},
						complete: () => {}
					})
					return;
				}
				
				if(_this.checkPicsFormRequired() == false){
					console.log("有图片上传不完整,请退出重新提交");
					return;
				}
				try{
					allPicsForm = _this.genPicsForm();
				}catch(err){
					uni.showToast({
						title: "获取图片上传表单失败:"+JSON.stringify(err),
						icon: "none"
					});
					return;
				}
				//zjj debug
				//return;
				QSApp.getForm(_this.formName).then(res=>{
					console.log('获取表单数据成功:' + JSON.stringify(res));
					if(res.verifyErr.length>0){
						let errInput = res.verifyErr[0];
						QSApp.showToast(errInput.title + "输入不正确");
						return;
					}
					
					if(_this.isCommiting){
						uni.showToast({
							title: "正在提交...",
							icon: "none"
						});
						return;
					}
					// console.log("----");
					console.log( res.data.passType.data[0].value);
					console.log( res.data.carType.data[0].value);
					let params = {
						passType: res.data.passType.data[0].value,
						carType:  res.data.carType.data[0].value,
						
						//startAddress: res.data.startAddress.data[0].value,
						//入城点根据陈勇要求存入的是字典name 而不是 code
						startAddress: res.data.startAddress.data[0].name,
						
						//startAddress: res.data.startAddress,
						endAddress: res.data.endAddress,
						appStartTime: res.data.appStartTime.data+":00:00",
						appEndTime: res.data.appEndTime.data+":00:00",
						
						carNum: res.data.carNum.data,
						subordinateType: res.data.subordinateType,
						subordinateUnit: res.data.subordinateUnit,
						driverName: res.data.driverName,
						contactNumber: res.data.contactNumber,
						driverIdCard: res.data.driverIdCard,
						appTheReason: res.data.appTheReason,
						allPicsJson: JSON.stringify(allPicsForm)
					};
					
					console.log('post表单数据:' + JSON.stringify(params));
					
					let url = "/rest/passApply";
					
					uni.showLoading({
						title:"提交表单，请您耐心等待..."
					})
					_this.isCommiting = true;
					_this.$api.request(url, params, failres => {
						_this.isCommiting = false;
						uni.hideLoading();
						uni.showToast({
							title: "服务器异常",
							icon: "none"
						});
					}).then(rsp => {
						console.log(rsp);
						_this.isCommiting = false;
						uni.hideLoading();
						//表单提交成功
						//提交图片
						//let passCheckRequestId = rsp.data.passCheckRequestId;
						uni.showModal({
							title: '提示',
							content: '申请通行证提交成功，请等待审核，审核通过后即可入城！',
							showCancel: false,
							confirmText: '确认',
							success: (e) => {
								if (e.confirm) {
									uni.navigateTo({
										url: '/pages/index/index'
									})
								}
							},
							fail: () => {},
							complete: () => {
								loginLock = false
							}
						})
						//_this.uploadAllPics(passCheckRequestId);
					})
					
				}).catch(err=>{
					console.log('获取表单数据失败:' + JSON.stringify(err));
					uni.showToast({
						title: "请检查表单数据",
						icon: "none"
					});
				});
			},
			
			loadDicts(){
				//加载字典信息
				let _this = this;
				let url = "/rest/getBizDicts";
				_this.$api.request(url, {}, failres => {
					uni.showToast({
						title: "服务器异常",
						icon: "none"
					});
				}).then(rsp => {
					//console.log(rsp);
					//第一步载入字典
					_this.setPickerData(rsp.data);
					//第二步载入历史数据
					_this.loadOldData();
				})
			},
			
			setPickerData(dics) {
				let _this = this;
				
				_this.passTypePickerData[0] = new Array();
				_this.carTypePickerData[0] = new Array();
				_this.startAddressPickerData[0] = new Array();
				

				//console.log(dics.passTypeDict);
				for (var item of dics.passTypeDict) {
						//console.log(item);
						_this.passTypePickerData[0].push(
							{
								name: item.name,
								value: item.code
							}
						);
				}

				for (var item of dics.carTypeDict) {
						//console.log(item);
						_this.carTypePickerData[0].push(
							{
								name: item.name,
								value: item.code
							}
						);
				}
				
				for (var item of dics.entTownTypeDict) {
						//console.log(item);
						_this.startAddressPickerData[0].push(
							{
								name: item.name,
								value: item.code
							}
						);
				}
				this.setPickerDataFc('passTypePicker', _this.passTypePickerData);
				this.setPickerDataFc('carTypePicker', _this.carTypePickerData);
				this.setPickerDataFc('startAddressPicker', _this.startAddressPickerData);
			},
			setPickerDataFc(name, data) {
				//console.log('准备 调用setData');
				console.log('准备 调用setData:'+JSON.stringify(data));
				this.$refs[name].setData(data);
			},
			loadOldData(){
				let _this = this;
				
				let params = {};
				let url = "/rest/passInfo";
				
				if(_this.reqId==null){
					return;
				}
				params.id = _this.reqId;
				_this.$api.request(url, params, failres => {
					uni.showToast({
						title: "服务器异常",
						icon: "none"
					});
				}).then(rsp => {
					console.log('获取表单数据成功:' + JSON.stringify(rsp));
					if(rsp.code == 200){
						//true success
						_this.fillPics(rsp.data.dynamic);
						_this.fillForms(rsp.data.detail);
					}
					
				})
			},
			fillForms(detail){
				let _this = this;


				//_this.$refs.passTypePicker.setValue(v);		
				for(let i =0;i<_this.passTypePickerData[0].length;i++){
					if(detail.passType ==  _this.passTypePickerData[0][i].value){
						const obj ={
								data: new Array(),
								value: new Array(),
							};
						obj.data.push(_this.passTypePickerData[0][i]);
						obj.value.push(i);
						_this.$refs.passTypePicker.setDataValue(obj);
					}
				}
				
				for(let i =0;i<_this.carTypePickerData[0].length;i++){
					if(detail.carType ==  _this.carTypePickerData[0][i].value){
						const obj ={
								data: new Array(),
								value: new Array(),
							};
						obj.data.push(_this.carTypePickerData[0][i]);
						obj.value.push(i);
						_this.$refs.carTypePicker.setDataValue(obj);
					}
				}
				///入城点根据陈勇要求存入的是字典name 而不是 code
				for(let i =0;i<_this.startAddressPickerData[0].length;i++){
					if(detail.startAddress ==  _this.startAddressPickerData[0][i].name){
						const obj ={
								data: new Array(),
								value: new Array(),
							};
						obj.data.push(_this.startAddressPickerData[0][i]);
						obj.value.push(i);
						_this.$refs.startAddressPicker.setDataValue(obj);
					}
				}
				
				

				_this.$refs.carNumRef.setDataValue(detail.carNum);
				
				_this.values.carType = detail.carType;
				_this.values.startAddress = detail.startAddress;
				//_this.values.appStartTime = detail.appStartTime;
				//_this.values.appEndTime = detail.appEndTime;				
				_this.$refs.endAddressRef.setValue( detail.endAddress);
				//_this.$refs.carNumRef.setValue( detail.carNum);
				if(detail.subordinateType=="" || detail.subordinateType == undefined){
					_this.$refs.subordinateTypeRef.setValue('0');
				}else{
					_this.$refs.subordinateTypeRef.setValue( detail.subordinateType);
				}

				_this.$refs.subordinateUnitRef.setValue( detail.subordinateUnit);
				_this.$refs.driverNameRef.setValue( detail.driverName);
				_this.$refs.contactNumberRef.setValue( detail.contactNumber);
				_this.$refs.driverIdCardRef.setValue( detail.driverIdCard);
				_this.$refs.appTheReasonRef.setValue( detail.appTheReason);
				
			},
			
			getPicsItem(fieldName){
				let _this = this;
				let it = null;
				
				_this.picsItemArray.forEach(item=>{
					if(item.fieldName == fieldName){
						it = item
					}
				})
				
				return it
			},
			fillPics(dynamic){
				let _this = this;
				//debugger;
				dynamic.forEach((item,index,array)=>{
					
					//执行代码 去除前缀4个数字字符 + _ 
					let fieldName = item.fieldName.substring(5)
					let it = _this.getPicsItem(fieldName);
					if(it!=null && it.type === "QSPics"){
						if(item.sort < it.vModeData.length){
							it.vModeData[item.sort].id = item.fieldValue;
							it.vModeData[item.sort].preFile = true;
							it.vModeData[item.sort].path = _this.clacPath(item);
							
							// let refStr = it.fieldName + 'PicsInf'
							// let inf = _this.$refs[refStr][0];
							// inf.setData(it.vModeData);
						}
					}else if(it!=null){
						it.vModeData.push({
								id: item.fieldValue,
								preFile: true,
								path: _this.clacPath(item)
						})
						
						// let refStr = it.fieldName + 'PicsInf'
						// let inf = _this.$refs[refStr][0];
						// inf.addPreData({
						// 		id: item.fieldValue,
						// 		preFile: true,
						// 		path: _this.clacPath(item)
						//  });
					}
				})
				//强制刷新更新
				_this.picsItemArray.forEach(item=>{
					if(item.required){
						item.required = false;
						item.required = true;
					}
				})
				
				// _this.updatePicsItem("spb",true);
				// _this.updatePicsItem("sfz",true);
				// _this.updatePicsItem("jsz",true);
				// _this.updatePicsItem("xsz",true);
				// _this.updatePicsItem("jqx",true);
				
			},
			clacPath(item){
				let _this = this;
				//debugger;
				if(item == null || 
					item == undefined ||
					item.filePath == undefined ||
					item.filePath == ''){
					
					return  _this.$api.defConfig().baseUrl + "/mh5/static/imgs/ktjingcha.png";
				}
				
				
				//console.log(JSON.stringify(item));
				let url = _this.$api.defConfig().baseUrl +"/upimg/"+ item.filePath;
				//console.log(url);
				
				return url;
			},
		}
	}
</script>

<style>
	
	.dirver-info-box{
		margin: 20upx 20upx;
		 border: 1px dashed #999999;
	}
	.dirver-info-box .title{
		margin-left:20upx;
		color: #999999;
	}
	
	
.passRule{
	text-align: right;
	font-size: 24upx;
	margin-top: 50upx;
	margin-right: 40upx;
	margin-bottom: 40upx;
	color: #DD524D;
	label{
		margin-left: 40upx;
	}
}

.passRuleTips{
	position: fixed;
	top: 0px;
	bottom: 0px;
	background-color: #F8F6FC;
	overflow:scroll; 
}

.tips-head{
	margin-top: 100upx;
	margin-right: 50upx;
	text-align: right;
}

.pass-rule-item{
	
	margin: 50upx 50upx;
}

.title-l1{
	font-weight: 1000;
	font-size: 32upx;
}

.title-l2{
	font-weight: 800;
	font-size: 28upx;
	margin-top: 15upx;
}

.content-section{
	font-weight: 500;
	font-size: 26upx;
	margin-top: 5upx;
}


</style>
